package com.sumainfor.pc.gmio.service.impl;

import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.CompuUtils;
import com.sumainfor.pc.gmio.dao.ButlerTableMapper;
import com.sumainfor.pc.gmio.dao.RentSupervisorsDeskMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcEpcFeign;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.gmio.service.RentSupervisorsDeskService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 租后主管工作台
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-06-05 17:37
 **/
@Service
public class RentSupervisorsDeskServiceImpl implements RentSupervisorsDeskService {

  @Autowired
    RentSupervisorsDeskMapper rentSupervisorsDeskMapper;

  @Autowired
    ZpcMktFeign zpcMktFeign;

  @Autowired
    ZpcEpcFeign zpcEpcFeign;

  @Autowired
  ButlerTableMapper butlerTableMapper;

    /**
    * <p>
    * 重要状态提醒
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @Override
    public JsonResult getImport(){
        JsonResult result = new JsonResult();

      //待分配管家
        JsonResult zpcmktResult = zpcMktFeign.getAssignHousekeeperCount();
        Map<String,Object> zpcmktMap = (Map<String, Object>) zpcmktResult.get("result");
          Map<String,Object> gmioMap =rentSupervisorsDeskMapper.getImport();
          Integer getYuqiCount = MapUtils.getInteger(gmioMap,"getYuqiCountone")+MapUtils.getInteger(gmioMap,"getYuqiCountTwo");
          gmioMap.put("getYuqiCount",getYuqiCount);
          gmioMap.put("getAssignHousekeeperCount",zpcmktMap.get("getAssignHousekeeperCount"));
        return result.put(gmioMap);
    }

    /**
    * <p>
    * 特殊消息提醒
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @Override
    public JsonResult specialConsiderations(){
        JsonResult result =new JsonResult();
        //JsonResult zpcepcResult = zpcEpcFeign.getNoRepairOrderCount(params);
        JsonResult zpcepcResult = zpcEpcFeign.getNoRepairOrderInteger();
        Map<String,Object> map = new HashMap<>();
        //超72小时未维修工单(租后主管)
      Map<String,Object> zpcepcMap = (Map<String, Object>) zpcepcResult.get("result");
    // map.put("getNoRepairOrderCount",zpcepcMap.get("getNoRepairOrderCount"));
        map.put("getNoRepairOrderInteger",zpcepcMap.get("getNoRepairOrderInteger"));
        //房源配置变化
        JsonResult zpcMktResult = zpcMktFeign.getHouConPactListCount();
        Map<String,Object> zpcMktMap = (Map<String, Object>) zpcMktResult.get("result");
        map.put("getHouConPactListCount",zpcMktMap.get("getHouConPactListCount"));
        //智能设备异常
        Integer getSmartDevicesCount =rentSupervisorsDeskMapper.getSmartDevicesCount();
        map.put("getSmartDevicesCount",getSmartDevicesCount);
        //训房异常回访
        JsonResult zpcMktResultOne = zpcMktFeign.getRoundsAbnormalCount();
        Map<String,Object> zpcMktOneMap = (Map<String, Object>) zpcMktResultOne.get("result");
        map.putAll(zpcMktOneMap);





        //未审核账单
        Map<String,Object> params = new HashMap<>();
        params.put("user_id", ContextUtils.getUserId());
        Integer getBillReviewTenant = butlerTableMapper.getBillReviewTenant();
        map.put("getBillReviewTenant",getBillReviewTenant);
        //待保洁房源
        Integer getNoClean = butlerTableMapper.getNoClean(params);
        map.put("getNoClean",getNoClean);
        //新房验收未通过
        params.put("SysUserId",params.get("user_id"));
        System.out.println("params"+params);

        JsonResult resultEpc2 = zpcEpcFeign.getNoacceptance(params);
        Map<String,Object> epcMap =(Map<String, Object>) resultEpc2.get("result");



        System.out.println(resultEpc2+"asssssssssssssssssssss");


        map.putAll(epcMap);


        return result.put(map);









    }


    /**
    * <p>
    * 日账审核
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @Override
    public JsonResult getToReviewBill(){
        //今日已审核
        List<Map<String,Object>> ToReviewBillOneList =rentSupervisorsDeskMapper.ToReviewBillOne();
        //待审核
        List<Map<String,Object>> ToReviewBillTwoList =rentSupervisorsDeskMapper.ToReviewBillTwo();
        JsonResult result = new JsonResult();
         Map<String,Object> map = new HashMap<>();
        double billOne =0.0;
     double billTwo =0.0;
       if (ToReviewBillOneList.size()>0) {
           for (Map<String, Object> ToReviewBillOneMap : ToReviewBillOneList) {
              billOne = CompuUtils.add(billOne,MapUtils.getDouble(ToReviewBillOneMap,"BiMoney"));

           }
       }

        if (ToReviewBillTwoList.size()>0) {
            for (Map<String, Object> ToReviewBillTwoMap : ToReviewBillTwoList) {
                billTwo =CompuUtils.add(billTwo,MapUtils.getDouble(ToReviewBillTwoMap,"BiMoney"));
            }

        }
            map.put("billOne",billOne);
        map.put("billTwo",billTwo);
      return result.put(map);
    }




}
